package spring.boot.btc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import spring.boot.btc.service.WalletService;

@RestController
@RequestMapping("/wallet")
public class WalletController {

    @Autowired
    private WalletService walletService;

    @GetMapping("balance")
    public long balance() {
        return walletService.getBalance();
    }

    @GetMapping("trans")
    public String trans(String account, long money) {
        long res = walletService.trans(account, money);
        if (-1 == res) {
            return "余额小于转账目标金额，余额不足！";
        }
        if (-2 == res) {
            return "自己不能给自己转账！";
        }
        return "转账成功！转账金额为=[" + money + "] 账户剩余金额=[" + walletService.getBalance() + "]";
    }

}
